#include <bits/stdc++.h>
using namespace std;
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
string ans[100000];
string s1[10] = {"jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren", "gui"};
string s2[12] = {"zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen", "you", "xu", "hai"};
int solve()
{
    string s;
    cin >> s;
    
    int t = 1, d = 1;
    for (int i = 0; i <=1000;i++)
    {
        ans[i] = s1[i%10] + s2[i%12];
    }
    for (int i = 0; i <= 1000;i++)
    {
        if(ans[i]==s)
        {
            return 1984+i;
        }
    }
}
int main()
{
    int t = 1;
    cin >> t;
    while (t--)
    {
        cout << solve() << endl;
    }
    return 0;
}
